﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Medianamik.UI;
using Medianamik.Core;
using Medianamik.Core.Redirect;
using System.Collections.Generic;
using Medianamik.UI.Controls;
using Medianamik.Core.Logging;
using Telerik.Web.UI;

namespace Medianamik.UI.RedirectManagement
{
    public partial class ExternalRedirectionsList : BaseModuleListPage 
    {
        protected string Filter
        {
            get
            {
                return ViewState["Filter"] as string ?? string.Empty;
            }
            private set
            {
                ViewState["Filter"] = value;
            }
        }

        protected void ApplyFilter(object sender, GridColumnFilterEventArgs e)
        {
            Filter = e.Value;
            GridRedirect.Rebind();
        }

        protected override void GridNeedDataSource(object source, 
            GridNeedDataSourceEventArgs e)
        {
            var nodes = ConfigManager.GetAll<ExternalRedirectNode>()
                .Where(n => (n.RedirectFrom ?? string.Empty).ToLowerInvariant().Contains(Filter))
                .OrderBy(n => n.RedirectFrom);

            GridRedirect.DataSource = nodes;
        }

        protected override RadGrid Grid
        {
            get { return GridRedirect; }
        }

        protected override UpdatePanel GridUpdatePanel
        {
            get { return RedirectPanel; }
        }

        protected override string ManagementURL
        {
            get { return "/medianamik/redirectmanagement/externalredirectionmanagement.aspx"; }
        }

        protected override string ReturnUrl
        {
            get { return "/medianamik/redirectmanagement/ExternalRedirectionsList.aspx"; }
        }
    }
}
